package com.adinnet.admin.course.service.impl;

import com.adinnet.admin.course.model.Course;
import com.adinnet.admin.course.mapper.CourseMapper;
import com.adinnet.admin.course.model.vo.CourseResp;
import com.adinnet.admin.course.service.CourseService;
import com.adinnet.admin.sentence.mapper.SentenceMapper;
import com.adinnet.admin.sentence.model.Sentence;
import com.adinnet.admin.system.model.vo.SysUserInfo;
import com.adinnet.admin.video.mapper.VideoMapper;
import com.adinnet.admin.video.model.Video;
import com.adinnet.admin.word.mapper.WordMapper;
import com.adinnet.admin.word.model.Word;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {


    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private WordMapper wordMapper;

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private SentenceMapper sentenceMapper;

    /**
     * @Description:  课程列表-分页
     * @author zYshuai
     * @Date: 2020/12/14 16:34
    * @param keyword:
    * @return: java.util.List<com.adinnet.admin.course.model.vo.CourseResp>
     */
    @Override
    public PageResult<CourseResp> courseList(String keyword, Integer page, Integer limit) {
        Page<CourseResp> objectPage = new Page<>(page, limit);
        List<CourseResp> respList = courseMapper.courseList(objectPage,keyword);
        return new PageResult<>(respList, objectPage.getTotal());
    }

    /**
     * @Description:  课程列表-不分页
     * @author zYshuai
     * @Date: 2020/12/14 16:41
    * @param sysUserInfo:
    * @return: java.util.List<com.adinnet.admin.course.model.Course>
     */
    @Override
    public List<Course> getListByUserRole(SysUserInfo sysUserInfo) {
        return courseMapper.selectList(new QueryWrapper<Course>().eq("deleted",0).orderByDesc("created_date"));
    }

    /**
     * @param courseId:
     * @Description: 删除课程
     * @author zYshuai
     * @Date: 2020/12/15 9:16
     * @return: com.adinnet.core.JsonResult
     */
    @Override
    @Transactional
    public JsonResult delete(Integer courseId) {
        courseMapper.updateStatus(courseId);
        videoMapper.updateStatus(courseId);
        sentenceMapper.updateStatus(courseId);
        wordMapper.updateStatus(courseId);
        return JsonResult.ok("删除成功!");
    }
}
